package com.cqjtu.eecs.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqjtu.eecs.entity.Project;
import com.cqjtu.eecs.entity.vo.GoalRequirementVO;
import com.cqjtu.eecs.exception.ParamsErrorException;
import com.cqjtu.eecs.service.IGoalRequirementService;
import com.cqjtu.eecs.service.IProjectService;
import com.cqjtu.eecs.utils.Assert;
import com.cqjtu.eecs.utils.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 培养目标-毕业要求 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/goal-requirement")
@Api(tags = "年级毕业要求-培养目标矩阵")
public class GoalRequirementController {

    @Autowired
    private IGoalRequirementService goalRequirementService;

    @Autowired
    private IProjectService projectService;

    @Autowired
    private ObjectMapper objectMapper;

    @ApiOperation("通过专业代码和年级获取年级毕业要求-培养目标矩阵")
    @GetMapping("/getGoalRequirementByCodeAndGrade/{majorCode}/{year}")
    public Result getGoalRequirementByPid(@PathVariable("majorCode")String majorCode, @PathVariable("year")String year)
    {
        Assert.notBlank(majorCode, new ParamsErrorException("专业代码不能为空"));
        Assert.notBlank(year, new ParamsErrorException("年级不能为空"));
        Project project= projectService.getOne(new QueryWrapper<Project>().eq("major_code",majorCode).eq("grade",year));
        if(project == null)
            return null;
        String pid=project.getPid().toString();
        //return goalRequirementService.getGoalRequirementByPid(pid);
        return Result.success(goalRequirementService.getGoalRequirementByPid(pid));
    }


}
